//
//  ZMYSettingHeadView.m
//  奇阅
//
//  Created by 奇阅科技 on 14-10-27.
//  Copyright (c) 2014年 奇阅科技. All rights reserved.
//

#import "ZMYSettingHeadView.h"
#import "Config.h"
@interface ZMYSettingHeadView()
{
    CGRect initialFrame;
    CGFloat defaultViewHeight;
}
@end
@implementation ZMYSettingHeadView
-(void)awakeFromNib{
    CAShapeLayer *maskLayer = [CAShapeLayer layer];
    maskLayer.backgroundColor = [UIColor whiteColor].CGColor;
    UIBezierPath *layerPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 75, 75)];
    maskLayer.path = layerPath.CGPath;
    maskLayer.fillColor = [UIColor blackColor].CGColor;
    self.headImageView.layer.mask = maskLayer;
    self.headImageView.clipsToBounds = YES;
    [self.headImageView addImageFullViewAnimation];
}
-(void)refreshPosition:(void(^)(void))headRefresh{
    self.handleRefreshEvent = headRefresh;
}
- (void)stretchHeaderForTableView:(UICollectionView*)collectionView withView:(UIView*)view
{
    _collectionView = collectionView;
    _view = view;
//    __weak typeof(self) weakSelf = self;
//    _collectionView.delegate = weakSelf;
    initialFrame       = _view.frame;
    defaultViewHeight  = _view.frame.size.height;
    
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView{
    if (_view.frame.size.height>400) {
        if (self.handleRefreshEvent) {
            self.handleRefreshEvent();
        }
    }
}
- (void)scrollViewDidScroll:(UIScrollView*)scrollView
{
    CGRect f = _view.frame;
    f.size.width = _collectionView.frame.size.width;
    _view.frame = f;
    
    if(scrollView.contentOffset.y < 0) {
        CGFloat offsetY = (scrollView.contentOffset.y + scrollView.contentInset.top) * -1;
        initialFrame.origin.y = offsetY * -1;
        initialFrame.size.height = defaultViewHeight + offsetY;
        _view.frame = initialFrame;
    }
}

- (void)resizeView
{
    initialFrame.size.width = _collectionView.frame.size.width;
    _view.frame = initialFrame;
}
-(void)initInfoLabel{
    UserAccount *user = [UserAccount currentAccount];
    if (user.uid.length>1) {
        self.loginButton.hidden = YES;
        if (user.headimg.length>1) {
            [self.headImageView setImageWithURL:[NSURL URLWithString:user.headimg]placeholderImage:[UIImage imageNamed:@"touxiang"]];
        } else {
            self.headImageView.image = [UIImage imageNamed:@"touxiang"];
        }
        self.nickNameLabel.hidden = NO;
        if (user.nickname.length>1) {
            self.nickNameLabel.text = user.nickname;
        } else {
            self.nickNameLabel.text = user.username;
        }
        if ([user.is_baoyue isEqualToString:@"1"]) {
            self.baoyueImageView.hidden = NO;
        } else {
            self.baoyueImageView.hidden = YES;
        }
        self.infoLabel.hidden = NO;
        self.infoLabel.text = [NSString stringWithFormat:@"余额:%@阅币 • 积分:%@积分",user.remain,user.points];
        self.levelLabel.hidden = NO;
        self.levelLabel.text = [NSString stringWithFormat:@"Lv %@",user.vip_level];
        self.hadBuyNumLabel.text = user.hadBuyNum;
        if (user.hadBuyNum.length<1||[user.hadBuyNum isEqualToString:@"0"]) {
            self.hadBuyNumLabel.text = @"--";
        }
        self.bookReviewNumLabel.text = user.bookReviewNum;
        if (user.bookReviewNum.length<1||[user.bookReviewNum isEqualToString:@"0"]) {
            self.bookReviewNumLabel.text = @"--";
        }
        self.collectionNumLabel.text = user.collectionNum;
        if (user.collectionNum.length<1||[user.collectionNum isEqualToString:@"0"]) {
            self.collectionNumLabel.text = @"--";
        }
    } else {
        self.headImageView.image = [UIImage imageNamed:@"touxiang"];
        self.loginButton.hidden = NO;
        self.levelLabel.hidden = YES;
        self.nickNameLabel.hidden = YES;
        self.infoLabel.hidden = YES;
        self.baoyueImageView.hidden = YES;
        self.hadBuyNumLabel.text = @"--";
        self.bookReviewNumLabel.text = @"--";
        self.collectionNumLabel.text = @"--";
    }
}



@end
